<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <button id="readName">读取name</button>
        <button id="readAge">读取age</button>
        <button id="setName">设置name</button>
        <button id="setAge">设置age</button>
        <p id="objName"></p>
        <script type="module">
            import { reactive, effect } from "./main.js";

            const data = {
                name: "张三",
                age: 25,
            };
            const obj = reactive(data);
            effect(() => {
                objName.innerHTML = obj.name;
                console.log(`触发副作用函数-name1`, obj.name);
            });
            effect(() => {
                console.log(`触发副作用函数-name2`, obj.name);
            });
            effect(() => {
                console.log(`触发副作用函数-age`, obj.age);
            });

            readName.onclick = function readVal() {
                console.log(`output->name`, obj.name);
            };
            readAge.onclick = function readVal() {
                console.log(`output->age`, obj.age);
            };
            setName.onclick = function readVal() {
                obj.name = `张三${Math.random()}`;
            };
            setAge.onclick = function readVal() {
                obj.age = Math.floor(Math.random() * 90 + 10);
            };
        </script>
    </body>
</html>
